package edu.task.repository;

import edu.task.model.SysUserMsg;
import edu.task.model.SysUserMsgPK;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface SysUserMsgRepository extends JpaRepository<SysUserMsg, SysUserMsgPK> {

    @Modifying
    @Query(value = "delete tm from sys_task_msg as tm " +
            "inner join sys_task as t on tm.task_id = t.task_id " +
            "inner join sys_msg as m on tm.msg_id = m.msg_id " +
            "where tm.task_id=:taskId ", nativeQuery = true)
    void deleteTaskMsgByTaskId(Long taskId);

    @Modifying
    @Query(value = "delete um from sys_user_msg as um " +
            "inner join sys_user as u on um.user_id = u.user_id " +
            "inner join sys_msg as m on um.msg_id = m.msg_id " +
            "where um.msg_id=:msgId ", nativeQuery = true)
    void deleteUserMsgById(Long msgId);
}
